<?php

namespace App\Exports\Weather;

use Maatwebsite\Excel\Concerns\FromCollection;

class WeatherExport implements FromCollection
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        //
        $data[] = [
            '城市',
            '时间',
            '周几',
            '天气',
            '温度'
        ];

        $weatherInterface = resolve('App\Repositories\Contracts\WeatherInterface');
        $where = [
            ['date','>=',date('Y-m-d')]
        ];
        $weathers = $weatherInterface->get($where,'*',['city']);
        if ($weathers->isNotEmpty()) {
            foreach ($weathers as $value) {

                $data[] = [
                    $value['city']['city_code'],
                    $value['date'],
                    $value['week'],
                    $value['weather'],
                    $value['temperature']
                ];
            }
        }

        return collect($data);

    }
}
